home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / _weakrefset.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  9KB  |  241 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. from _weakref import ref
  5. __all__ = [
  6.     'WeakSet']
  7.  
  8. class _IterationGuard(object):
  9.     
  10.     def __init__(self, weakcontainer):
  11.         self.weakcontainer = ref(weakcontainer)
  12.  
  13.     
  14.     def __enter__(self):
  15.         w = self.weakcontainer()
  16.         if w is not None:
  17.             w._iterating.add(self)
  18.         return self
  19.  
  20.     
  21.     def __exit__(self, e, t, b):
  22.         w = self.weakcontainer()
  23.         if w is not None:
  24.             s = w._iterating
  25.             s.remove(self)
  26.             if not s:
  27.                 w._commit_removals()
  28.             
  29.  
  30.  
  31.  
  32. class WeakSet(object):
  33.     
  34.     def __init__(self, data = None):
  35.         self.data = set()
  36.         
  37.         def _remove(item, selfref = ref(self)):
  38.             self = selfref()
  39.             if self is not None:
  40.                 if self._iterating:
  41.                     self._pending_removals.append(item)
  42.                 else:
  43.                     self.data.discard(item)
  44.  
  45.         self._remove = _remove
  46.         self._pending_removals = []
  47.         self._iterating = set()
  48.         if data is not None:
  49.             self.update(data)
  50.  
  51.     
  52.     def _commit_removals(self):
  53.         l = self._pending_removals
  54.         discard = self.data.discard
  55.         while l:
  56.             discard(l.pop())
  57.  
  58.     
  59.     def __iter__(self):
  60.         with _IterationGuard(self):
  61.             for itemref in self.data:
  62.                 item = itemref()
  63.                 if item is not None:
  64.                     yield item
  65.                     continue
  66.  
  67.     
  68.     def __len__(self):
  69.         return len(self.data) - len(self._pending_removals)
  70.  
  71.     
  72.     def __contains__(self, item):
  73.         
  74.         try:
  75.             wr = ref(item)
  76.         except TypeError:
  77.             return False
  78.  
  79.         return wr in self.data
  80.  
  81.     
  82.     def __reduce__(self):
  83.         return (self.__class__, (list(self),), getattr(self, '__dict__', None))
  84.  
  85.     __hash__ = None
  86.     
  87.     def add(self, item):
  88.         if self._pending_removals:
  89.             self._commit_removals()
  90.         self.data.add(ref(item, self._remove))
  91.  
  92.     
  93.     def clear(self):
  94.         if self._pending_removals:
  95.             self._commit_removals()
  96.         self.data.clear()
  97.  
  98.     
  99.     def copy(self):
  100.         return self.__class__(self)
  101.  
  102.     
  103.     def pop(self):
  104.         if self._pending_removals:
  105.             self._commit_removals()
  106.         while True:
  107.             
  108.             try:
  109.                 itemref = self.data.pop()
  110.             except KeyError:
  111.                 raise KeyError('pop from empty WeakSet')
  112.  
  113.             item = itemref()
  114.             if item is not None:
  115.                 return item
  116.  
  117.     
  118.     def remove(self, item):
  119.         if self._pending_removals:
  120.             self._commit_removals()
  121.         self.data.remove(ref(item))
  122.  
  123.     
  124.     def discard(self, item):
  125.         if self._pending_removals:
  126.             self._commit_removals()
  127.         self.data.discard(ref(item))
  128.  
  129.     
  130.     def update(self, other):
  131.         if self._pending_removals:
  132.             self._commit_removals()
  133.         for element in other:
  134.             self.add(element)
  135.         
  136.  
  137.     
  138.     def __ior__(self, other):
  139.         self.update(other)
  140.         return self
  141.  
  142.     
  143.     def difference(self, other):
  144.         newset = self.copy()
  145.         newset.difference_update(other)
  146.         return newset
  147.  
  148.     __sub__ = difference
  149.     
  150.     def difference_update(self, other):
  151.         self.__isub__(other)
  152.  
  153.     
  154.     def __isub__(self, other):
  155.         if self._pending_removals:
  156.             self._commit_removals()
  157.         if self is other:
  158.             self.data.clear()
  159.         else:
  160.             self.data.difference_update((lambda .0: pass)(other))
  161.         return self
  162.  
  163.     
  164.     def intersection(self, other):
  165.         return (self.__class__,)((lambda .0: pass)(other))
  166.  
  167.     __and__ = intersection
  168.     
  169.     def intersection_update(self, other):
  170.         self.__iand__(other)
  171.  
  172.     
  173.     def __iand__(self, other):
  174.         if self._pending_removals:
  175.             self._commit_removals()
  176.         self.data.intersection_update((lambda .0: pass)(other))
  177.         return self
  178.  
  179.     
  180.     def issubset(self, other):
  181.         return self.data.issubset((lambda .0: pass)(other))
  182.  
  183.     __le__ = issubset
  184.     
  185.     def __lt__(self, other):
  186.         return self.data < set((lambda .0: pass)(other))
  187.  
  188.     
  189.     def issuperset(self, other):
  190.         return self.data.issuperset((lambda .0: pass)(other))
  191.  
  192.     __ge__ = issuperset
  193.     
  194.     def __gt__(self, other):
  195.         return self.data > set((lambda .0: pass)(other))
  196.  
  197.     
  198.     def __eq__(self, other):
  199.         if not isinstance(other, self.__class__):
  200.             return NotImplemented
  201.         return None.data == set((lambda .0: pass)(other))
  202.  
  203.     
  204.     def __ne__(self, other):
  205.         opposite = self.__eq__(other)
  206.         if opposite is NotImplemented:
  207.             return NotImplemented
  208.         return not None
  209.  
  210.     
  211.     def symmetric_difference(self, other):
  212.         newset = self.copy()
  213.         newset.symmetric_difference_update(other)
  214.         return newset
  215.  
  216.     __xor__ = symmetric_difference
  217.     
  218.     def symmetric_difference_update(self, other):
  219.         self.__ixor__(other)
  220.  
  221.     
  222.     def __ixor__(self, other):
  223.         if self._pending_removals:
  224.             self._commit_removals()
  225.         if self is other:
  226.             self.data.clear()
  227.         else:
  228.             (self.data.symmetric_difference_update,)((lambda .0: pass)(other))
  229.         return self
  230.  
  231.     
  232.     def union(self, other):
  233.         return self.__class__((lambda .0: pass)((self, other)))
  234.  
  235.     __or__ = union
  236.     
  237.     def isdisjoint(self, other):
  238.         return len(self.intersection(other)) == 0
  239.  
  240.  
  241.